package mx.com.basi.bsn;

import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;

public class BsnLecturaImagen  {
    

  
    public static void main(String[] args) {
    	    
    	Image Imagen = null;
    	BufferedImage ImagenBuffer = null;
    	
    	int alto = 0;
    	int ancho = 0;
    	
    	 Imagen = Toolkit.getDefaultToolkit().getImage("C:\\Imagen.jpg");
    	 ImagenBuffer = BsnLecturaImagen.toBufferedImage(Imagen);
    	 
    	 System.out.println( alto = ImagenBuffer.getHeight() );
    	 System.out.println( ancho = ImagenBuffer.getWidth() );
    	 
    	 
    	 for (int i = 0; i < alto; i++) {
			for (int j = 0; j < ancho; j++) {
				System.out.println(ImagenBuffer.getRGB(i, j) + " ");
			}
			System.out.println("\n");
		}
    	
	}
    
    
    
    static BufferedImage toBufferedImage(Image image) {
     
        if( image instanceof BufferedImage ) {
           
                return( (BufferedImage)image );
        } else {
               
                image = new ImageIcon(image).getImage();
             
                BufferedImage bufferedImage = new BufferedImage(
                                                      image.getWidth(null),
                                                      image.getHeight(null),
                                                      BufferedImage.TYPE_INT_RGB);
                Graphics g = bufferedImage.createGraphics();
                g.drawImage(image,0,0,null);
                g.dispose();
 
                return (bufferedImage);
        } 
 
    } 

   
    
} 
